import { message } from 'antd';

let messageInstance: ReturnType<typeof message.useMessage>[0] | null = null;

export const initGlobalMessage = () => {
  const [api, contextHolder] = message.useMessage();
  messageInstance = api;
  return contextHolder;
};

export const globalMessage = () => {
  if (!messageInstance) {
    throw new Error('请先调用 initGlobalMessage() 初始化！');
  }
  return messageInstance;
};
